package com.sl.au.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.sl.au.entity.Account;
import com.sl.au.entity.EXDEAgingLedgerAddOrReduce;
import com.sl.au.entity.EXDEgetPayDetailHistoryWithContract;
import com.sl.au.service.EXDEAgingLedgerAddOrReduceService;
import com.sl.au.service.EXDEgetPayDetailHistoryWithContractService;

/**
 * 新增减账龄台帐
 */
@RestController
@RequestMapping(value="/ui/payRegulationAgingAccount")
public class PayRegulationAgingAccountController extends BaseController{
    
	@Autowired
	EXDEAgingLedgerAddOrReduceService exdeAgingLedgerAddOrReduceService;
	
    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView index(){
        ModelAndView modelAndView=createLayoutView("paymentSearch/payRegulationAgingAccount");
        Account a = this.getMyAccount();
		String userId =a.getUser().getId();
		modelAndView.addObject("userId",userId);
		return modelAndView;
    }
    /**
     * 	返回数据json串
     * */
    @RequestMapping(value = "getFirst", method = RequestMethod.GET)
	public Map<String,Object> getMyTrance(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<String,Object>();
		Map<String,String> condition = new HashMap<String,String>();
		Account a = this.getMyAccount();
		int start = Integer.parseInt(request.getParameter("start"));
		int length = Integer.parseInt(request.getParameter("length"));
		//String chanceId = request.getParameter("chanceId");
		//String userId = a.getUser().getId();
		String superior = a.getUser().getSaleArea().getSuperior(); //部门
		//String superior = "销售处";
		String key = request.getParameter("key");
		List<EXDEAgingLedgerAddOrReduce> users = null;
		//String sContractType = request.getParameter("sContractType");
        //condition.put("chanceId", chanceId);
        //condition.put("userId", userId);
		condition.put("key", key);
		//condition.put("sContractType", sContractType);
		condition.put("superior", superior);
		users = exdeAgingLedgerAddOrReduceService.getMyPage(start, length, condition);
        long count = exdeAgingLedgerAddOrReduceService.getMyPageCount(start, length, condition);
		
		map.put("data", users);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}
    /**
     * 	获取当年当月和当部门
     * */
    @RequestMapping(value = "/getmypage", method = RequestMethod.GET)
	public Map<String, Object> getmypage(HttpServletRequest request) {
    	Map<String,Object> map1 = new HashMap<String,Object>();
    	Account a = this.getMyAccount();
    	String superior = a.getUser().getSaleArea().getSuperior(); //获取部门信息
		//String superior = "销售处";
		map1.put("superior", superior);
		return map1;
    }
}
